/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package probando;

import java.io.*;
import java.net.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrador
 */
public class cliente {

    public static String IP_SERVER;
   //VentCliente vent;
   DataInputStream entrada = null;
   DataOutputStream salida = null;
   DataInputStream entrada2 = null;
   Socket comunication = null;//para la comunicacion
   Socket comunication2 = null;//para recivir msg


   private String nomCliente;

    /**
     * @return the nomCliente
     */
    public //para recivir msg
    String getNomCliente() {
        return nomCliente;
    }

    /**
     * @param nomCliente the nomCliente to set
     */
    public void setNomCliente(String nomCliente) {
        this.nomCliente = nomCliente;
    }


    public void conexion() throws IOException
   {
      try {
         comunication = new Socket(cliente.IP_SERVER, 8081);
         comunication2 = new Socket(cliente.IP_SERVER, 8082);
         entrada = new DataInputStream(comunication.getInputStream());
         salida = new DataOutputStream(comunication.getOutputStream());
         entrada2 = new DataInputStream(comunication2.getInputStream());
         salida.writeUTF(nomCliente);
      } catch (IOException e) {
         System.out.println("\tEl servidor no esta levantado");
         System.out.println("\t=============================");
      }
      new hilocliente(entrada2).start();
   }
     public Vector<String> pedirUsuarios()
   {
      Vector<String> users = new Vector();
      try {
         salida.writeInt(2);
         int numUsers=entrada.readInt();
         for(int i=0;i<numUsers;i++)
            users.add(entrada.readUTF());
      } catch (IOException ex) {
         Logger.getLogger(cliente.class.getName()).log(Level.SEVERE, null, ex);
      }
      return users;
   }

}
